package com.example.ssss.ui.notifications;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.example.ssss.ContactActivity;
import com.example.ssss.DeviceActivity;
import com.example.ssss.PersonInfoActivity;
import com.example.ssss.SOSCardActivity;
import com.example.ssss.databinding.FragmentNotificationsBinding;

public class NotificationsFragment extends Fragment {

    private NotificationsViewModel notificationsViewModel;
    private FragmentNotificationsBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        notificationsViewModel =
                new ViewModelProvider(this).get(NotificationsViewModel.class);

        binding = FragmentNotificationsBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        setBtnsOnClick();

        /*final TextView textView = binding.textNotifications;
        notificationsViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                textView.setText(s);
            }
        });*/
        return root;
    }

    public void startPersonInfo(){//跳转到全屏检测页面
        Intent intent = null;
        intent = new Intent(getActivity(), PersonInfoActivity.class);
        this.startActivity(intent);
    }
    public void startSOSCard(){
        Intent intent = null;
        intent = new Intent(getActivity(), SOSCardActivity.class);
        intent.putExtra("data","fromNotification");
        this.startActivity(intent);
    }
    public void startContact(){
        Intent intent = null;
        intent = new Intent(getActivity(), ContactActivity.class);
        this.startActivity(intent);
    }
    public void startDevice(){
        Intent intent = null;
        intent = new Intent(getActivity(), DeviceActivity.class);
        this.startActivity(intent);
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    public void setBtnsOnClick() {
        Intent intent = null;
        LinearLayout personInfoBtn=binding.personInfoBtn;
        LinearLayout sosCardBtn=binding.sosCardBtn;
        LinearLayout contactBtn=binding.contactBtn;
        LinearLayout deviceBtn=binding.deviceBtn;
        //LinearLayout settingBtn=binding.settingBtn;
        LinearLayout helpBtn=binding.helpBtn;
        LinearLayout aboutBtn=binding.aboutBtn;

        personInfoBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startPersonInfo();
            }
        });
        sosCardBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startSOSCard();
            }
        });
        contactBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startContact();
            }
        });
        deviceBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startDevice();
            }
        });
//        settingBtn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                sentToast("抱歉，暂未开发 T-T",1);
//            }
//        });
        helpBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri content_url = Uri.parse("https://shimo.im/docs/VMAPVwLY4Wfb6nqg/");//此处填链接
                intent.setData(content_url);
                startActivity(intent);
            }
        });
        aboutBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sentToast("抱歉，暂未开发 T-T",1);
            }
        });
    }
    public void sentToast(String str, int showTime)
    {
        Toast toast = Toast.makeText(getContext(), str, showTime);
        toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL , 0, 0);  //设置显示位置
        //TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
        toast.show();
    }
}